<template>
  <view class="padding-bottom physical-examination">
    <view v-for="item in checkList" :key="item.id" class="box" @click="view(item)">
      <view class="box-content">
        <view class="box-content-name">{{ item.packageName }}</view>
        <view class="box-content-title">{{ item.productName }}</view>
      </view>
      <view :class="['box-btn', item.productStatus > 20 ? 'box-btn-disable' : '']">{{
        item.productStatus | statusTxt
      }}</view>
    </view>

    <view v-if="!checkList.length" class="zwjl"></view>

    <view class="tip"> 如需帮助，请致电 <text class="color"> 400-010-1516</text> </view>
  </view>
</template>

<script>
import { checkList } from '@/api/physicalExamination';
import { tongji } from '@/utils/tools';
import { commonProjectType } from '@/common/baseUrl.js';
export default {
  filters: {
    statusTxt: function (statue) {
      let txt = '';
      switch (statue) {
        case 10: // 未开始
          txt = '查看';
          break;
        case 20: // 进行中
          txt = '查看';
          break;
        case 99:
          txt = '已完成';
          break;
        case 98:
          txt = '已失效';
          break;

        default:
          txt = '未知';
          break;
      }
      return txt;
    }
  },
  data() {
    return {
      patientId: '',
      checkList: []
    };
  },

  onLoad: function (opt) {
    if (opt && opt.patientId) {
      this.patientId = opt.patientId;
      this.init();
    } else {
      uni.showModal({
        content: '参数错误',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            uni.reLaunch({
              url: 'pages/index/index'
            });
          }
        }
      });
      // this.patientId = '3dd45d7114af46ce80f9776c15083f66';
      // this.init();
    }
  },

  methods: {
    async init() {
      const res = await checkList(this.patientId);
      if (res.code === 0 && res.data && res.data.length) {
        this.checkList = res.data.filter((item) => item.projectType === commonProjectType);
      } else {
        uni.showToast(res.message);
      }
    },

    // 查看
    view(item) {
      if (item.productStatus > 20) return;
      const params = JSON.stringify(item);
      this.$wxPromise.navigateTo({
        url: `/pagesC/physicalExamination/detail?params=` + params + '&patientId=' + this.patientId
      });

      tongji('5e799fec-b497-4a2e-a515-9d2ea33ebdee');
    }
  }
};
</script>

<style lang="scss">
@import './../style/common.scss';
.physical-examination {
  padding: 24rpx;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: border-box;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  .box {
    background: #ffffff;
    border-radius: 12rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 32rpx 24rpx;
    box-sizing: border-box;
    margin-bottom: 24rpx;
    &-btn {
      width: 160rpx;
      height: 56rpx;
      border: 1px solid #f34e1c;
      border-radius: 32rpx;
      text-align: center;
      font-size: 24rpx;
      line-height: 56rpx;
      color: #f34e1c;
      &-disable {
        color: #b2b2b2;
        border: 1px solid #b2b2b2;
      }
    }
    &-content {
      flex: 1;
      &-name {
        font-size: 32rpx;
        font-weight: bold;
        margin-bottom: 18rpx;
      }
      &-title {
        font-size: 34rpx;
        padding-right: 16rpx;
      }
    }
  }

  .tip {
    text-align: center;
    color: rgba(0, 0, 0, 0.6);
    margin: 56rpx 0 40rpx;
    font-size: 28rpx;
    margin-top: auto;
    bottom: 0px;
    width: 100%;
    .color {
      font-weight: bold;
      color: #c8161d;
      padding-left: 10rpx;
    }
  }

  .no-content {
    opacity: 0.6;
    text-align: center;
    margin-top: 100rpx;
  }
}
</style>
